﻿using java.io;
using System;
using System.Globalization;
using System.Windows.Controls;
using yzrilyzr.asn1;
using yzrilyzr.crypto.keys;
using yzrilyzr.util;

namespace FAQ_UI
{
	public class PubkeyValidate : ValidationRule
	{
		public override ValidationResult Validate(object value, CultureInfo cultureInfo)
		{
			try
			{
				if (value == null || (string)value == "") { return new ValidationResult(false, "请输入公钥"); }
				byte[] base64 = Util.b64(value.ToString());
				string asn1value = ASN1.read(new ByteArrayInputStream(base64)).toString();
				try
				{
					Byte2Key.pubkey(base64);
					return new ValidationResult(true, "");
				}
				catch (Exception e) { return new ValidationResult(false, "暂不支持此公钥"); }
			}
			catch (Exception e) { return new ValidationResult(false, "无效的公钥"); }
		}
	}
}